package com.detech.sbom.base.log.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.detech.sbom.base.annotation.Log;
import com.detech.sbom.base.annotation.ProductSwagger;
import com.detech.sbom.base.config.mybatis.PageParam;
import com.detech.sbom.base.domain.R;
import com.detech.sbom.base.domain.RE;
import com.detech.sbom.base.enumtype.LogTypeEnum;
import com.detech.sbom.base.enumtype.ModuleEnum;
import com.detech.sbom.base.log.service.LogService;
import com.detech.sbom.base.mybatis.log.entity.TbLogP6spyEntity;
import com.detech.sbom.base.mybatis.log.entity.TbLogSysEntity;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/log")
@Api(tags = "日志管理")
public class LogController {

    @Autowired
    private LogService logService;

    @ApiOperation(value = "查询系统日志列表", notes = "查询系统日志列表")
    @ApiOperationSupport( author = "方安伦")
    @ApiImplicitParams({
            @ApiImplicitParam(name="content",value="日志内容",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="logType",value="日志类型（DEBUG、INFO、WARN、ERROR）",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="module",value="系统模块",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="operator",value="操作人",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="ip",value="IP地址",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="logTime",value="记录时间（yyyy-MM-dd）",dataType="string", dataTypeClass=java.lang.String.class, paramType = "query",required=false)
    })
    @ProductSwagger
    @RequestMapping(value = "/loadSysLogList",method = RequestMethod.POST)
    @Log(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询系统日志列表")
    public RE<Page<TbLogSysEntity>> loadSysLogList(@Validated PageParam pageParam, String content, String logType, String module, String operator, String ip, String logTime) {
        Page<TbLogSysEntity> logIPage = logService.loadSysLogList(pageParam,content,logType,module,operator,ip,logTime);
        return R.ok(logIPage);
    }

    @ApiOperation(value = "查询P6spy日志列表", notes = "查询P6spy日志列表")
    @ApiOperationSupport( author = "方安伦")
    @ApiImplicitParams({
            @ApiImplicitParam(name="ybySql",value="预编译SQL",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="paramSql",value="带参数SQL",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="xhsj",value="执行耗时（毫秒）",dataType="int", paramType = "query", dataTypeClass=java.lang.Integer.class,required=false),
            @ApiImplicitParam(name="xmmc",value="项目名",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false),
            @ApiImplicitParam(name="logTime",value="记录时间（yyyy-MM-dd）",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=false)
    })
    @ProductSwagger
    @RequestMapping(value = "/loadP6spyLogList",method = RequestMethod.POST)
    @Log(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询P6spy日志列表")
    public RE<Page<TbLogP6spyEntity>> loadP6spyLogList(@Validated PageParam pageParam, String ybySql, String paramSql, Integer xhsj, String xmmc, String logTime) {
        Page<TbLogP6spyEntity> logIPage = logService.loadP6spyLogList(pageParam,ybySql,paramSql,xhsj,xmmc,logTime);
        return R.ok(logIPage);
    }

    @ApiOperation(value = "查询系统日志详情", notes = "查询系统日志详情")
    @ApiOperationSupport( author = "方安伦")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="日志ID",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=true)
    })
    @ProductSwagger
    @RequestMapping(value = "/loadSysLogDetail",method = RequestMethod.POST)
    @Log(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询系统日志详情")
    public RE<TbLogSysEntity> loadSysLogDetail(String id) {
        TbLogSysEntity tbLogSysEntity = logService.loadSysLogDetail(id);
        return R.ok(tbLogSysEntity);
    }

    @ApiOperation(value = "查询P6spy日志详情", notes = "查询P6spy日志详情")
    @ApiOperationSupport( author = "方安伦")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="日志ID",dataType="string", paramType = "query", dataTypeClass=java.lang.String.class,required=true)
    })
    @ProductSwagger
    @RequestMapping(value = "/loadP6spyLogDetail",method = RequestMethod.POST)
    @Log(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询P6spy日志详情")
    public RE<TbLogP6spyEntity> loadP6spyLogDetail(String id) {
        TbLogP6spyEntity tbLogP6spyEntity = logService.loadP6spyLogDetail(id);
        return R.ok(tbLogP6spyEntity);
    }

}
